package org.mijia.dotsbox.rcp;

import org.eclipse.jface.resource.CompositeImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;

public class DecoratedImage extends CompositeImageDescriptor {

    private Image baseImage;
    private Image decoratedTag;
    private Point sizeOfImage;
    private int location;

    public static final int TOP_LEFT = 0;
    public static final int TOP_RIGHT = 1;
    public static final int BOTTOM_LEFT = 2;
    public static final int BOTTOM_RIGHT = 3;

    public DecoratedImage(Image baseImage, Image decTag, int loc) {
        this.baseImage = baseImage;
        this.decoratedTag = decTag;
        this.sizeOfImage = new Point(baseImage.getBounds().width, baseImage
                .getBounds().height);
        location = loc;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int,
     *      int)
     */
    protected void drawCompositeImage(int width, int height) {
        drawImage(baseImage.getImageData(), 0, 0);
        ImageData imageData = decoratedTag.getImageData();
        switch(location)
        {
          // Draw on the top left corner
          case TOP_LEFT:
            drawImage(imageData, 0, 0);
            break;
            
          // Draw on top right corner  
          case TOP_RIGHT:
            drawImage(imageData, sizeOfImage.x - imageData.width, 0);
            break;
            
          // Draw on bottom left  
          case BOTTOM_LEFT:
            drawImage(imageData, 0, sizeOfImage.y - imageData.height);
            break;
            
          // Draw on bottom right corner  
          case BOTTOM_RIGHT:
            drawImage(imageData, sizeOfImage.x - imageData.width,
                      sizeOfImage.y - imageData.height);
            break;
            
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.resource.CompositeImageDescriptor#getSize()
     */
    protected Point getSize() {
        return sizeOfImage;
    }
}
